<template>
	<view class="Give">
		<view style="flex:1;">
			<view class="list">
				<input type="text" placeholder="请输入对方的账户ID" v-model="accountid">
			</view>
		</view>
		<view class="but">
			<button class="savegive" @click="savegive">{{buttomtext}}</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				accountid: '',
				id: '',
				type: '',
				buttomtext: '确认转赠'
			};
		},
		onLoad: function(option) {
			//获取路由传值
			this.id = option.id;
			this.type = option.type;
			if (this.type === "gift") {
				uni.setNavigationBarTitle({
					title: '激活码转赠'
				});
				this.buttomtext = "确认转赠"
				return false;
			}
			if (this.type === "actv") {
				uni.setNavigationBarTitle({
					title: '激活码激活'
				});
				this.buttomtext = "确认激活"
				return false;
			}

		},
		methods: {

			savegive: function() {
				let _this = this;
				if (!_this.accountid) {
					uni.showToast({
						title: "请输入对方的账户ID",
						icon: "none",
						duration: 2000
					});
					return false;
				}
				//激活码转赠
				if (this.type === "gift") {
					const data = {
						cid: _this.id,
						user_id: _this.accountid
					}
					this.$request.post("/api/ucenter/sendCode", {
							data: data
						})
						.then(res => {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
							if (res.data.code == 1) {
								uni.navigateTo({
									url: '../ActivationCode/ActivationCode'
								})
							}
						})
						.catch(error => {
							console.error('error:', error);
						});
					return false;
				}
				//激活码激活
				if (this.type === "actv") {
					const data = {
						cid: _this.id,
						uid: _this.accountid
					}
					this.$request.post("/api/ucenter/activeUser", {
							data: data
						})
						.then(res => {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
							if (res.data.code == 1) {
								uni.navigateTo({
									url: '../ActivationCode/ActivationCode'
								})
							}
						})
						.catch(error => {
							console.error('error:', error);
						});
					return false;
				}


			}
		}
	}
</script>

<style lang="less">
	.Give {
		background-color: #F1F1F1;
		width: 100%;
		display: flex;
		flex-direction: column;

		.list {
			height: 60px;
			background-color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 20px;
			border-top: 5px solid #F1F1F1;
			font-size: 16px;
			color: #707070;

			input {
				display: block;
				width: 100%;
			}
		}

		.but {
			height: 120px;

			.savegive {
				width: 275px;
				height: 46px;
				background: rgba(29, 123, 255, 1);
				color: #fff;
				border-radius: 8px;
			}
		}
	}
</style>
